﻿using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 主界面
/// </summary>
public class MainCanvas : MonoBehaviour
{
    private Transform mNoticeTf;
    private Transform mScoreTf;
    private Text mScore;
    private Text mNotice;
    // Start is called before the first frame update
    void Start()
    {
        mNoticeTf = transform.Find("Notice");
        mScoreTf = transform.Find("Score");
        mScore = mScoreTf.Find("Value").GetComponent<Text>();
        mNotice = mNoticeTf.Find("Text").GetComponent<Text>();
        EventCenter.GetInstance().AddEventListener("ResetUI", ResetUI);
        EventCenter.GetInstance().AddEventListener<string>("Notify", Notify);
        EventCenter.GetInstance().AddEventListener<int>("Change Score", ChangeScore);
    }
    private void ResetUI()
    {
        ChangeScore(0);
        Notify("");
    }

    private void OnDestroy()
    {
        EventCenter.GetInstance().RemoveEventListener<string>("Notify", Notify);
        EventCenter.GetInstance().RemoveEventListener<int>("Change Score", ChangeScore);
    }
    /// <summary>
    /// 通知
    /// </summary>
    private void Notify(string text)
    {
        mNotice.text = text;
    }
    /// <summary>
    /// 更改分数
    /// </summary>
    private void ChangeScore(int score)
    {
        mScore.text = score + "";
    }
}
